<template>
  <home-block
    class="warrant"
    title="博金盾 - 火博网娱乐顶级第三方担保"
  >
    <div class="btn-wrap">
      <router-link to="/report">
        <img :src="`${$baseImgUrl}home/report.png`"/>
      </router-link>
      <router-link to="/guarantee">
        <img :src="`${$baseImgUrl}home/guarantee.png`"/>
      </router-link>
    </div>
    <van-row>
      <van-col :span="12">
        <div class="plat" :style="{background: `#f4f3f3 url('${$baseImgUrl}home/plat_bg.png') no-repeat`}">
          <p>
            已收入
            <router-link class="link" to="/company">{{plat.company}}</router-link>
            家
          </p>
          <p>
            已安全担保
            <router-link class="link" to="/guarantee">{{plat.guarantee}}</router-link>
            家
          </p>
          <p>
            已安全认证
            <router-link class="link" to="/guarantee">{{plat.certification}}</router-link>
            家
          </p>
        </div>
      </van-col>
      <van-col :span="12" class="record-wrap">
        <div class="record" :style="{background: `url('${$baseImgUrl}home/r_bg.png') no-repeat 0 center`}">交易记录</div>
          <div class="list-wrap">
            <ul class="list" :style="{transform: `translateY(${distance}px)`}">
              <li
                v-for="(record, index) in recordList"
                :key="index"
                :style="{background: `url('${$baseImgUrl}home/index_15.png') no-repeat 0 center`}"
              >
                {{record.number}} 充值 <span>{{record.money}}</span> 元
              </li>
            </ul>
          </div>
      </van-col>
    </van-row>
    <div class="warrant-list">
      <van-row :gutter="5">
        <van-col
          v-for="(sub, index) in warrantList"
          :key="index"
          :span="8"
          class="warrant-item"
        >
          <img class="big-img" :src="`${$baseImgUrl}home/${sub.img}`"/>
          <div class="text-wrap">
            <p>{{sub.text}}</p>
            <p v-if="sub.deposit">已缴纳保证金</p>
            <van-row class="btn-wrap">
              <van-col :span="12">
                <span>担保注册</span>
              </van-col>
              <van-col :span="12">
                <span>担保入款</span>
              </van-col>
            </van-row>
          </div>
        </van-col>
      </van-row>
    </div>
  </home-block>
</template>

<script>
import HomeBlock from './HomeBlock.vue';

export default {
  name: 'HomeWarrant',
  props: {
    plat: {
      type: Object,
      default() {
        return {
          company: 0,
          guarantee: 0,
          certification: 0
        };
      }
    },
    records: {
      type: Array,
      default() {
        return [
          { number: 'q***e', money: '10000.00' },
          { number: 'w***e', money: '9999.00' },
          { number: 'e***e', money: '9988.00' },
          { number: 'r***e', money: '1012.00' },
          { number: 't***e', money: '2034.00' }
        ];
      }
    },
    warrantList: {
      type: Array,
      default() {
        return [
          {
            img: 'warrant01.png', url: '', text: 'bet365', deposit: true
          },
          {
            img: 'warrant02.png', url: '', text: '皇冠现金网', deposit: true
          },
          {
            img: 'warrant03.png', url: '', text: '澳门新葡京', deposit: true
          },
          {
            img: 'warrant04.png', url: '', text: '新加坡金莎娱乐场', deposit: true
          },
          {
            img: 'warrant01.png', url: '', text: 'bet365', deposit: true
          },
          {
            img: 'warrant02.png', url: '', text: '皇冠现金网', deposit: true
          }
        ];
      }
    }
  },
  data() {
    return {
      distance: 0
    };
  },
  computed: {
    recordList() {
      return this.records.slice();
    },
    warrant() {
      const COUNT = 4;
      const pieces = Math.ceil(this.warrantList.length / COUNT);
      const res = [];
      for (let i = 0; i < pieces; i += 1) {
        res.push(this.warrantList.slice(i * COUNT, (i + 1) * COUNT));
      }
      return res;
    }
  },
  components: {
    HomeBlock
  },
  methods: {
    runRecords() {
      const DIATANCE = -26;
      const WAIT = 40;
      const unitDistance = 26 / 30;
      let wait = 0;
      const run = () => {
        if (this.distance <= DIATANCE) {
          if (wait >= WAIT) {
            wait = 0;
            this.distance = 0;
            this.recordList.push(this.recordList.shift());
          }
          wait += 1;
        } else {
          this.distance -= unitDistance;
        }
        requestAnimationFrame(run);
      };
      run();
    }
  },
  created() {
    this.runRecords();
  }
};
</script>

<style lang="less" scoped>
  .warrant {
    .btn-wrap {
      display: flex;
      a {
        flex: 1;
        text-align: center;
        img {
          width: 80%;
          border: 1px solid transparent;
        }
      }
    }
    .plat {
      margin-top: 1rem;
      padding-left: 38px;
      p {
        line-height: 32px;
        font-size: 1.2rem;
        a {
          padding: 0px 8px;
          font-size: 2.4rem;
          color: #FD6600;
          text-decoration: none;
          &:hover {
            text-decoration: underline;
          }
        }
      }
    }
    .record-wrap {
      margin-top: .5rem;
      padding-left: 1rem;
      .record {
        line-height: 30px;
        padding-left: 30px;
      }
    }
    .list-wrap {
      height: 80px;
      overflow: hidden;
      .list {
        margin-top: .5rem;
        li {
          margin: 0 0 10px 4px;
          padding-left: 24px;
          white-space: nowrap;
          span {
            color: #ff6600;
          }
        }
      }
    }
  }
  .warrant-list {
    margin-top: 1rem;
    .warrant-item {
      cursor: pointer;
      overflow: hidden;
      &:hover .btn-wrap {
        bottom: 0;
      }
      .big-img {
        width: 100%;
        height: 90px;
      }
    }
    .text-wrap {
      position: relative;
      margin-top: 3px;
      padding: 3px 0;
      text-align: center;
      background-color: #eee;
      font-size: 1.2rem;
      color: #333;
      p {
        line-height: 18px;
      }
      .btn-wrap {
        position: absolute;
        bottom: -4.1rem;
        width: 100%;
        transition: bottom 0.2s ease;
        .van-col {
          display: block;
          height: 4.1rem;
          line-height: 4.1rem;
          text-align: center;
          font-size: 1rem;
          background-color: #30A893;
          color: #fff;
          &:last-child {
            background-color: #358DAF;
          }
          span:hover {
            text-decoration: underline;
          }
        }
      }
    }
  }
</style>
